package com.zking.frame.zc;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

import com.zking.db.BaseDao;
import com.zking.utils.DoubleUtils;
import com.zking.utils.MyCalendar;
import com.zking.utils.StringUtils;
import com.zking.utils.TableUtils;



/**
 * 入库
 * 
 * @author ZC
 *
 */
public class SellJFrame extends JDialog {

	/**
	 * **
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// 美化包
	{
		try {
			BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
			org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	// 面板
	private JPanel pl;
	// 北部
	private JPanel pl_north;
	private JButton bt_add_bill;
	private JButton bt_update_bill;
	private JButton bt_delete_bill;// 增删改库单
	private JButton bt_add_goods;
	private JButton bt_delete_goods;// 增删改商品栏
	// 中部
	private JSplitPane split_center;
	private JPanel pl_center_left;
	private JPanel pl_center_right;
	// 表格
	private DefaultTableModel tableModel_left;
	private JTable table_left;// 左边库单的表格及模型
	private DefaultTableModel tableModel_right;
	private JTable table_right;// 右边商品栏的表格及模型
	String[] columnNames_right = { "书号", "书名", "作者", "定价","库存数量", "类别", "批发数量", "合计金额"};// 表格头
	String[] columnNames_left = { "编号","批发单号", "客户id","客户", "批发日期", "备注" };// 表格头
    //SQL
	private String insertOfLib="insert into wholesale(id,wholeSaleNum,customerId,wholeSaleDate) values(?,?,?,?)";
	private String queryOfLib="select id,wholeSaleNum,customerId,wholeSaleDate,notes from wholesale";
	private String insertOfLibC="insert into wholesalecontent(wholeSaleId,bookId,wholeSaleNum) values(?,?,?)";
	private BaseDao base=new BaseDao();//数据库操作
	private int libNum;//入库单
	{
		try {
			libNum=base.getCount("select max(id) from wholesale")+1;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	// 南部
	private JPanel pl_south;
	private JButton bt_sell_goods;// 销售商品按钮
	private JLabel lb_totalMoney;
	private JTextField tf_totalMoney;// 合计金额
	private JLabel lb_realMoney;
	private JTextField tf_realMoney;// 实收金额
	private JLabel lb_discount;
	private JTextField tf_discount;// 批发折扣

	// 边框
	private Border border = BorderFactory.createMatteBorder(0, 0, 3, 2, Color.gray);
	// 颜色
	private Color blue = new Color(0x9FB6CD);

	// 日期
	private String pattern = "yyyy-MM-dd";// 日期格式化模板

	// 辅助
	private JLabel temp;// 调整间距
    private Map<String,String> memberMap=new HashMap<String, String>();//会员信息
    private Map<String,String> goodsMap=new HashMap<String, String>();//商品信息
    private Map<String,String> libListMap=new HashMap<String, String>();//库单信息
    /**
	 * 1.填充批发单数据
	 */
	public void fillData() {
		try {
			List<Object[]> data=base.queryArrayListHandler(queryOfLib);//库单信息
			for(int i=0;i<data.size();i++) {//添加到面板，但少了客户名
				String client_id=data.get(i)[2]+"";
				String client_name="临时客户";
				if(client_id.length()!=0&&!"".equals(client_id)&&!"null".equals(client_id)) {
					client_name=base.queryArrayHandler("select name from client where id=?",client_id)[0]+"";
				}
				Object[] rowData=new Object[columnNames_left.length];
				for(int j=0;j<data.get(i).length;j++) {
					if(j<3) {
						rowData[j]=data.get(i)[j];
					}else if(j==3) {
						rowData[j]=client_name;
						rowData[j+1]=data.get(i)[j];
					}else {
						rowData[j+1]=data.get(i)[j];
					}
				}
				tableModel_left.addRow(rowData);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 2.添加数据库库单内容到面板
	 */
	public void showLibData() {
		tableModel_right.setDataVector(null, columnNames_right);//清空数据
		int  lib_id=Integer.parseInt(tableModel_left.getValueAt(table_left.getSelectedRow(),0)+"");//获取选中行（库单）
		try {
			List<Object[]> libc=base.queryArrayListHandler("select bookId,wholeSaleNum from "
					         + "wholesalecontent where wholeSaleId=?",lib_id);//根据库单ID查找书籍号与批发数
			for(int i=0;i<libc.size();i++) {//找书
				String sql="select id,BookName,author,price,inventoryNums,type from bookinfo where id=?";
				Object[] books=base.queryArrayHandler(sql,libc.get(i)[0]);
				List<Object> list=new ArrayList<Object>();
				for(int j=0;j<books.length;j++) {
					list.add(books[j]);
				}
				list.add(libc.get(i)[1]);//批发数量
				list.add((int)libc.get(i)[1]*(double)(books[3]));
				tableModel_right.addRow(list.toArray());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 3.计算总金额
	 */
	public void setTotalMoney() {
		double totalMoney=0;
		for(int i=0;i<tableModel_right.getRowCount();i++) {
			totalMoney+=Double.parseDouble(tableModel_right.getValueAt(i, columnNames_right.length-1)+"");
		}
		tf_totalMoney.setText(DoubleUtils.doubleFormat(totalMoney,"#0.00"));
		tf_realMoney.setText(DoubleUtils.doubleFormat(totalMoney*0.85,"#0.00"));
	}
	/**
	 * 批发销售面板
	 * 
	 * @param owner 父面板
	 * @param modal
	 */
	public SellJFrame(JFrame owner, boolean modal) {
		super(owner, modal);
		Container c = getContentPane();
		c.setLayout(new BorderLayout());
		/* 整个面板 */
		pl = new JPanel();
		pl.setBackground(Color.WHITE);
		pl.setLayout(new BorderLayout());

		/* 顶部 */
		pl_north = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 15));
		pl_north.setBackground(blue);
		pl_north.setPreferredSize(new Dimension(0, 50));
		c.add(BorderLayout.NORTH, pl_north);

		// 新增批发单
		bt_add_bill = new JButton("新增批发单");
		bt_add_bill.setPreferredSize(new Dimension(100, 30));
		bt_add_bill.setFont(new Font("楷体", Font.BOLD, 15));
		bt_add_bill.setBackground(new Color(0xF0F0F0));
		bt_add_bill.setOpaque(false);
		bt_add_bill.setBorder(border);
		bt_add_bill.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_add_bill.addActionListener(e -> {
			new ChooseMember(SellJFrame.this, true,memberMap);//弹出选择客户窗
			if (memberMap.size() == 0)//没有会员信息
				return;
			String memberID;
			String memberName;
			if("".equals((memberID=memberMap.get("memberID")))) {//没有客户号
				memberName="临时客户";
				memberID=null;
			}else {//有客户号
				 memberName=memberMap.get("memberName");//客户名
			}
			memberMap.clear();//清空集合
			//设置批发单表格的信息
			String today=StringUtils.dateToString(new Date(), pattern);//今天
			String[] rowData = {libNum+"",today.replace("-","")+String.format("%04d",libNum),memberID,memberName,today};
			tableModel_left.addRow(rowData);
			int final_row = tableModel_left.getRowCount() - 1;
			table_left.setRowSelectionInterval(final_row, final_row);// 选中新增行
			table_left.scrollRectToVisible(table_left.getCellRect(final_row, 0, true));// 滚动条随选中行移动
			tableModel_right.setDataVector(null, columnNames_right);//清空数据
			//添加到数据库
			try {
				base.update(insertOfLib,libNum+"",today.replace("-","")+String.format("%04d",libNum),memberID,today);
				libNum++;
				JOptionPane.showMessageDialog(SellJFrame.this,"增加成功");
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}   
		});
		pl_north.add(bt_add_bill);
		// 修改入批发单
		bt_update_bill = new JButton("修改批发单");
		bt_update_bill.setPreferredSize(new Dimension(100, 30));
		bt_update_bill.setFont(new Font("楷体", Font.BOLD, 15));
		bt_update_bill.setBackground(new Color(0xF0F0F0));
		bt_update_bill.setBorder(border);
		bt_update_bill.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_update_bill.addActionListener(e -> {
			int selectRow;
			if ((selectRow=table_left.getSelectedRow()) != -1) {
				libListMap.put("memberNameOfLib",(String)tableModel_left.getValueAt(selectRow,3));
				libListMap.put("noteOfLib",(String)tableModel_left.getValueAt(selectRow,5));
				libListMap.put("memberID",tableModel_left.getValueAt(selectRow,2)+"");
				new LibraryList(SellJFrame.this,true,libListMap);
				//更新数据库
				try {
					base.update("update wholesale set customerId=?,wholeSaleDate=?,notes=? where id=?",
							                          tableModel_left.getValueAt(selectRow, 2),
							                          tableModel_left.getValueAt(selectRow, 4),
							                          tableModel_left.getValueAt(selectRow, 5),
							                          tableModel_left.getValueAt(selectRow, 0));
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			} else {
				JOptionPane.showMessageDialog(SellJFrame.this, "请选中所需修改的批发单");
			}
		});
		pl_north.add(bt_update_bill);
		// 删除入批发单 1.批发单 2.批发单内容 3.回复书籍数量
		bt_delete_bill = new JButton("删除入批发单");
		bt_delete_bill.setPreferredSize(new Dimension(100, 30));
		bt_delete_bill.setFont(new Font("楷体", Font.BOLD, 15));
		bt_delete_bill.setBackground(new Color(0xF0F0F0));
		bt_delete_bill.setBorder(border);
		bt_delete_bill.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_delete_bill.addActionListener(e -> {
			int selectRow;
			if ((selectRow = table_left.getSelectedRow()) != -1) {
				if (JOptionPane.showConfirmDialog(SellJFrame.this, "确认要删除吗？", "提示",
						JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
					//更新数据库
					try {
						String  lib_id=table_left.getValueAt(selectRow, 0)+"";//库单ID
						//更新书籍库存
						{
							List<Object[]> bookIDs=base.queryArrayListHandler("select bookid,wholeSaleNum from wholesalecontent where wholeSaleId=?",lib_id);//查询所有库单书号,批发数
						    for(int i=0;i<bookIDs.size();i++) {
						    	int bookNum=base.getCount("select inventoryNums from bookinfo where id=?",bookIDs.get(i)[0]);//查询图书库存
						    	base.update("update bookinfo set inventoryNums=? where id=?",(int)bookNum+(int)bookIDs.get(i)[1],bookIDs.get(i)[0]);//修改图书库存
						    }
						}
						base.update("delete from wholesalecontent where wholeSaleId=?",lib_id);//删除库单内容
						System.out.println("id="+lib_id);
						base.update("delete from wholesale where id=?",lib_id);//删除库单
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					//移除面板
					tableModel_left.removeRow(selectRow);// 移除
					JOptionPane.showMessageDialog(SellJFrame.this, "删除成功");
				}
			} else {
				JOptionPane.showMessageDialog(SellJFrame.this, "请选中所需删除的库单");
			}
		});
		pl_north.add(bt_delete_bill);
		// 添加商品 1.批发内容的数量  2.书籍减少
		bt_add_goods = new JButton("增加商品");
		bt_add_goods.setPreferredSize(new Dimension(100, 30));
		bt_add_goods.setFont(new Font("楷体", Font.BOLD, 15));
		bt_add_goods.setBackground(new Color(0xF0F0F0));
		bt_add_goods.setBorder(border);
		bt_add_goods.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_add_goods.addActionListener((e) -> {
			int selectRow;//批发单行
			if ((selectRow=table_left.getSelectedRow()) != -1) {
				goodsMap.clear();
				new Goodsfarme(SellJFrame.this, true,goodsMap);//goodsmap商品信息
				//将选择的商品添加到商品表格中
				if(goodsMap.isEmpty()) return ;
				String  bookNum=(String)goodsMap.get("bookNum");//书号
				String  bookName=(String)goodsMap.get("bookName");//书名
				String  bookAuthor=(String)goodsMap.get("bookAuthor");
				String bookPrice=(String)goodsMap.get("bookPrice");
				String bookNumOfSell=(String)goodsMap.get("bookNumOfSell");//批发数量
				String bookNumOfLib=(String)goodsMap.get("bookNumOfLib");//库存数量
				       bookNumOfLib=Integer.parseInt(bookNumOfLib)-Integer.parseInt(bookNumOfSell)+"";
				String bookType=(String)goodsMap.get("bookType");
				String totalMoney=DoubleUtils.doubleFormat(Integer.parseInt(bookNumOfSell)*Double.parseDouble(bookPrice),"#.00");
				String[] rowData= {bookNum,bookName,bookAuthor,bookPrice,bookNumOfLib,bookType,bookNumOfSell,totalMoney};
				tableModel_right.addRow(rowData);
				goodsMap.clear();
				//选中新增行
				int new_row = tableModel_right.getRowCount() - 1;
				table_right.setRowSelectionInterval(new_row, new_row);// 选中新增行
				table_right.scrollRectToVisible(table_right.getCellRect(new_row, 0, true));// 滚动条随选中行移动
				//写到数据库 1.批发单的批发数 2.书籍库存数量
				try {
					base.update(insertOfLibC,tableModel_left.getValueAt(selectRow, 0),bookNum,bookNumOfSell);
					//insertOfLibC="insert into wholesalecontent(wholeSaleId,bookId,wholeSaleNum) values(?,?,?)";
					base.update("update bookinfo set inventoryNums=? where id=?",bookNumOfLib,bookNum);
				} catch (Exception e2) {
					// TODO: handle exception
					e2.printStackTrace();
				}	
				setTotalMoney();
				JOptionPane.showMessageDialog(SellJFrame.this, "添加成功");
			}
			else
				JOptionPane.showMessageDialog(SellJFrame.this, "请选中所需操作的库单");
		});
		pl_north.add(bt_add_goods);
		// 删除商品
		bt_delete_goods = new JButton("删除商品项");
		bt_delete_goods.setPreferredSize(new Dimension(100, 30));
		bt_delete_goods.setFont(new Font("楷体", Font.BOLD, 15));
		bt_delete_goods.setBackground(new Color(0xF0F0F0));
		bt_delete_goods.setBorder(border);
		bt_delete_goods.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_delete_goods.addActionListener(e -> {
			int selectRow;
			if ((selectRow = table_right.getSelectedRow()) != -1) {
				if (JOptionPane.showConfirmDialog(SellJFrame.this, "确认要删除吗？", "提示",
						JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
					try {
						String  bookID=tableModel_right.getValueAt(table_right.getSelectedRow(),0)+"";
						String  wholeNum=tableModel_right.getValueAt(table_right.getSelectedRow(),columnNames_right.length-2)+"";
						Object[] libc_id=base.queryArrayHandler("select id from wholesalecontent where wholeSaleId=? and bookId=? and wholeSaleNum=?",//查找库存内容ID
								                                                 tableModel_left.getValueAt(table_left.getSelectedRow(),0),//库单ID
								                                                                                          bookID,wholeNum);
					System.out.println("库单ID="+tableModel_left.getValueAt(table_left.getSelectedRow(),0)+
								       "书籍ID="+bookID+
								       "批发数量="+wholeNum);
					base.update("delete from wholesalecontent where id=?",libc_id[0]);//删除库单内容表
					Object[] bookNum=base.queryArrayHandler("select inventoryNums from bookinfo where id=?",bookID);//获取图书库存
					base.update("update bookinfo set inventoryNums=? where id=?",Integer.parseInt(bookNum[0]+"")+Integer.parseInt(wholeNum),bookID);//还原图书库存
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						return ;
					}
					tableModel_right.removeRow(selectRow);// 移除
					setTotalMoney();
					JOptionPane.showMessageDialog(SellJFrame.this, "删除成功");
				}
			} else {
				JOptionPane.showMessageDialog(SellJFrame.this, "请选中所需删除的商品项");
			}
		});
		pl_north.add(bt_delete_goods);
		temp = new JLabel();// 间距
		temp.setPreferredSize(new Dimension(150, 10));
		pl_north.add(temp);

//		// 1.重置批发数量
//		JLabel lb_update_num = new JLabel("重置批发数量:");// 商品数量标签
//		lb_update_num.setFont(new Font("楷体", Font.BOLD, 15));
//		pl_north.add(lb_update_num);
//		// 1.1输入框
//		tf_update_num = new JTextField(10);
//		tf_update_num.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
//		tf_update_num.setFont(new Font("宋体", Font.PLAIN, 15));
//		tf_update_num.setPreferredSize(new Dimension(0, 25));
//		pl_north.add(tf_update_num);
//		// 1.2修改数量
//		bt_update_num = new JButton("重置");
//		bt_update_num.setPreferredSize(new Dimension(50, 30));
//		bt_update_num.setFont(new Font("楷体", Font.BOLD, 15));
//		bt_update_num.setBackground(new Color(0xF0F0F0));
//		bt_update_num.setBorder(border);
//		bt_update_num.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
//		bt_update_num.addActionListener(e -> {
//			int selectRow;
//			if ((selectRow = table_right.getSelectedRow()) != -1) {
//				try {
//					int updateNum = Integer.parseInt(tf_update_num.getText());// 重置数
//					tableModel_right.setValueAt(updateNum+"", selectRow, 4);
//					JOptionPane.showMessageDialog(SellJFrame.this, "重置成功!!!");
//					tf_update_num.setText("");
//				} catch (Exception e2) {
//					JOptionPane.showMessageDialog(SellJFrame.this, "请输入数字且为整数");
//					return ;
//				}
//			} else {
//				JOptionPane.showMessageDialog(SellJFrame.this, "请选中所需修改的商品项");
//				return ;
//			}
//		});
//		pl_north.add(bt_update_num);
		/* 中部 */
		split_center = new JSplitPane();
		split_center.setDividerSize(6);
		split_center.setDividerLocation(300);
		split_center.setOneTouchExpandable(true);
		c.add(BorderLayout.CENTER, split_center);
		// 左边
		pl_center_left = new JPanel(new BorderLayout());
		pl_center_left.setBackground(Color.white);
		split_center.setLeftComponent(pl_center_left);
		// 表格
		tableModel_left = new DefaultTableModel(columnNames_left, 0) {
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isCellEditable(int row, int column) {
				// TODO Auto-generated method stub
				return false;
			}
		};
		table_left = new JTable(tableModel_left);
		table_left.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				showLibData();
				setTotalMoney();
			}
		});
		JScrollPane sp_center_left = new JScrollPane(table_left);
		sp_center_left.getViewport().setOpaque(false);
		sp_center_left.setBackground(Color.WHITE);
		pl_center_left.add(BorderLayout.CENTER, sp_center_left);

		// 右边
		pl_center_right = new JPanel(new BorderLayout());
		pl_center_right.setBackground(Color.white);
		split_center.setRightComponent(pl_center_right);
		// 表格

		tableModel_right = new DefaultTableModel(columnNames_right, 0) {
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isCellEditable(int row, int column) {
				// TODO Auto-generated method stub
				return false;
			}
		};
		table_right = new JTable(tableModel_right);
		JScrollPane sp_center_right = new JScrollPane(table_right);
		sp_center_right.getViewport().setOpaque(false);
		sp_center_right.setBackground(Color.WHITE);
		pl_center_right.add(BorderLayout.CENTER, sp_center_right);

		/* 底部 */
		pl_south = new JPanel(new FlowLayout(FlowLayout.RIGHT, 30, 10));
		pl_south.setBackground(blue);
		pl_south.setPreferredSize(new Dimension(0, 50));
		c.add(BorderLayout.SOUTH, pl_south);
		// 批发折扣
//		lb_discount;
//	    tf_discount;//批发折扣
		JPanel pl_discount = new JPanel(new FlowLayout());// 设置边框用的
		pl_discount.setBorder(BorderFactory.createDashedBorder(Color.red, 1, 5f, 2, true));
		pl_discount.setOpaque(false);// 去掉颜色
		pl_south.add(pl_discount);
		lb_discount = new JLabel("批发折扣:");// 合计标签
		lb_discount.setFont(new Font("楷体", Font.BOLD, 15));
		pl_discount.add(lb_discount);
		tf_discount = new JTextField(15);// 合计输入框
		tf_discount.setHorizontalAlignment(JTextField.CENTER);
		tf_discount.setText("0.85");
		tf_discount.setEditable(false);
		tf_discount.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		tf_discount.setFont(new Font("宋体", Font.PLAIN, 15));
		tf_discount.setPreferredSize(new Dimension(0, 20));
		pl_discount.add(tf_discount);
		// 金钱
		JPanel pl_money = new JPanel(new FlowLayout());// 设置边框用的
		pl_money.setBorder(BorderFactory.createLineBorder(Color.white, 1));
		pl_money.setOpaque(false);// 去掉颜色
		pl_south.add(pl_money);
		lb_totalMoney = new JLabel("合计:");// 合计标签
		lb_totalMoney.setFont(new Font("楷体", Font.BOLD, 15));
		pl_money.add(lb_totalMoney);
		tf_totalMoney = new JTextField(15);// 合计输入框
		tf_totalMoney.setEditable(false);
		tf_totalMoney.setHorizontalAlignment(JTextField.CENTER);
		tf_totalMoney.setText("0.00");
		tf_totalMoney.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		tf_totalMoney.setFont(new Font("宋体", Font.PLAIN, 15));
		tf_totalMoney.setPreferredSize(new Dimension(0, 20));
		pl_money.add(tf_totalMoney);
		lb_realMoney = new JLabel("实收:");// 应收标签
		lb_realMoney.setFont(new Font("楷体", Font.BOLD, 15));
		pl_money.add(lb_realMoney);
		tf_realMoney = new JTextField(15);// 应收输入框
		tf_realMoney.setEditable(false);
		tf_realMoney.setHorizontalAlignment(JTextField.CENTER);
		tf_realMoney.setText("0.00");
		tf_realMoney.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		tf_realMoney.setFont(new Font("宋体", Font.PLAIN, 15));
		tf_realMoney.setPreferredSize(new Dimension(0, 20));
		pl_money.add(tf_realMoney);
		// 出售商品
		bt_sell_goods = new JButton("出售商品");
		bt_sell_goods.setPreferredSize(new Dimension(100, 30));
		bt_sell_goods.setFont(new Font("楷体", Font.BOLD, 15));
		bt_sell_goods.setBackground(new Color(0xF0F0F0));
		bt_sell_goods.setBorder(border);
		bt_sell_goods.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bt_sell_goods.addActionListener(e -> {
			int selectRow;
			if ((selectRow = table_left.getSelectedRow()) != -1) {
				if (JOptionPane.showConfirmDialog(SellJFrame.this, "确认要出售吗？出售后记录不可见", "提示",
						JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
					tableModel_left.removeRow(selectRow);// 移除
				    tableModel_right.setDataVector(null,columnNames_right);
			} else {
				JOptionPane.showMessageDialog(SellJFrame.this, "请选中所需出售的批发单");
			}
		});
		pl_south.add(bt_sell_goods);
		
//		fillData();// 填充数据
		TableUtils.interlacedColorChange(table_left,new Color(0xFFFFF0),new Color(0xFFFACD));//隔行换色
		TableUtils.interlacedColorChange(table_right,new Color(0xFFFFE0),new Color(0xFFFACD));
		setTitle("批发销售");
		setSize(1025, 685);
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		setLocationRelativeTo(owner);
		setVisible(true);

	}

	public static void main(String[] args) {
		new SellJFrame(null, true);
	}

	/**
	 * 修改库单界面
	 * 
	 * @author ZC
	 *
	 */
	class LibraryList extends JDialog {

		private static final long serialVersionUID = 1L;
		private Font font;

		private JPanel pl_flow;
		private JLabel lb;// 头标前
		private JLabel lb_name;// 客户name
		private JButton bt_member;//客户选择选择
		private JLabel lb_sellDate;
		private JLabel lb_note;
		private JTextField tf_name;
		private JTextField tf_sellDate;
		private JTextField tf_note;

		private JButton bt_sure;// 修改
		private JButton bt_cancel;// 取消
		private String memberName;
		private String memberID;

		/**
		 * 1.通过插入无文字透明标签调整距理（仅限于流式布局）
		 * @param width
		 * @param height
		 * @param c 需要调整的组件
		 */
		public void insertJLabel(int width,int height,Container c) {
			JLabel lb=new JLabel();
			lb.setPreferredSize(new Dimension(width,height));
//			lb.setOpaque(true);
//			lb.setBackground(Color.red);
			c.add(lb);
		}
		/**
		 * 2.创建带文字的按钮
		 * @param text
		 * @return
		 */
		public JButton createJButton(String text) {
			JButton bt=new JButton();
			bt=new JButton(text);
	        bt.setPreferredSize(new Dimension(90, 30));
			bt.setFont(new Font("楷体",Font.BOLD,15));
			bt.setBackground(new Color(0xF0F0F0));
			bt.setBorder(border);
			bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			return bt;
		}
		public JButton createJButton(String text,int width) {
			JButton bt=new JButton();
			bt=new JButton(text);
	        bt.setPreferredSize(new Dimension(width, 30));
			bt.setFont(new Font("楷体",Font.BOLD,15));
			bt.setBackground(new Color(0xF0F0F0));
			bt.setBorder(border);
			bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			return bt;
		}
		/**
		 * 3.填充修改前数据（name,note,时间为当前时间）
		 * @param libListMap
		 */
		public void  init(Map<String,String> libListMap) {
			if(!libListMap.isEmpty()) {
				tf_name.setText(memberName=libListMap.get("memberNameOfLib"));//
				tf_note.setText(libListMap.get("noteOfLib"));
				tf_sellDate.setText(StringUtils.dateToString(new Date(), pattern));
				memberID=libListMap.get("memberID");
				libListMap.clear();
			}
		}
		public LibraryList(JDialog frame, boolean modal,Map<String,String> libListMap) {
			super(frame, modal);
			font = new Font("宋体", Font.BOLD, 18);

			Container c = getContentPane();
			Color color0 = new Color(74, 101, 132);
			c.setBackground(color0);
			c.setLayout(new FlowLayout());
			//顶部间隔
            insertJLabel(650,25,c);
			// 中部面板
			pl_flow = new JPanel(new FlowLayout(FlowLayout.LEFT));// 流布局
			pl_flow.setPreferredSize(new Dimension(650, 220));
			Color color1 = new Color(222, 231, 239);
			pl_flow.setBackground(color1);
			c.add(pl_flow);
            //1.标题
			//1.1间距 
			insertJLabel(270,20, pl_flow);
			//1.2标题
			lb = new JLabel("批发单修改");
			lb.setFont(font);
			lb.setPreferredSize(new Dimension(350, 40));
			pl_flow.add(lb);
            
			//2.客户
			//2.1客户标签
			lb_name = new JLabel("     客户:");
			lb_name.setFont(font);
			lb_name.setPreferredSize(new Dimension(100, 40));
			pl_flow.add(lb_name);
            //2.2客户显示栏
			tf_name = new JTextField();
			tf_name.setFont(font);
			tf_name.setEditable(false);;
			Color color2 = new Color(255, 255, 225);
			tf_name.setPreferredSize(new Dimension(350, 25));
			tf_name.setBackground(color2);
			tf_name.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_name);
			//2.3客户选择按钮
            bt_member=createJButton("点此选择客户",140);
            bt_member.addActionListener(e->{
            	memberMap.clear();//清空
            	new ChooseMember(LibraryList.this, true,memberMap);//弹出选择客户面板
            	if (memberMap.size() == 0) {//没有选择客户（即点击了取消，或者直接关闭了所弹出的窗口）
            		memberName=null;
            		return;
            	}
    			if("".equals((memberID=memberMap.get("memberID")))) {//非会员
    				memberName="临时客户";
    				memberID=null;
    			}else {
    				 memberName=memberMap.get("memberName");//有客户号
    			}
    			memberMap.clear();//清空集合
    			tf_name.setText(memberName);
            });
            pl_flow.add(bt_member);
            
            //3.批发日期
			lb_sellDate = new JLabel(" 批发日期:");
			lb_sellDate.setFont(font);
			lb_sellDate.setPreferredSize(new Dimension(100, 40));
			pl_flow.add(lb_sellDate);
            //3.2日期输入框
			tf_sellDate = new JTextField();
			tf_sellDate.setFont(font);
			tf_sellDate.setPreferredSize(new Dimension(495, 25));
			tf_sellDate.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			MyCalendar ser =MyCalendar.getInstance();//日历
			ser.register(tf_sellDate);
			tf_sellDate.setEditable(false);
			pl_flow.add(tf_sellDate);
             
			//那条横线
			insertJLabel(100, 1, pl_flow);
			JLabel label2 = new JLabel();// 填充板
			label2.setPreferredSize(new Dimension(495, 3));
			label2.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			pl_flow.add(label2);

			//4.备注
			lb_note = new JLabel("     备注:");
			lb_note.setFont(font);
			lb_note.setPreferredSize(new Dimension(100, 40));
			pl_flow.add(lb_note);
			
            //4.2备注输入
			tf_note = new JTextField();
			tf_note.setFont(font);
			tf_note.setPreferredSize(new Dimension(495, 25));
			tf_note.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			pl_flow.add(tf_note);
			
			//5.确认，取消
			insertJLabel(600, 20, c);//调整间距
			bt_sure=createJButton("确定");
			bt_sure.addActionListener(e->{
				if(memberName==null||"".equals(memberName)||memberName.length()==0||"null".equals(memberName)) {
					JOptionPane.showMessageDialog(LibraryList.this,"请先选择客户");
					return ;
				}
				String sell_date=tf_sellDate.getText();
				String note=tf_note.getText();//备注
				//设置批发单表格的信息
				int selectRow=table_left.getSelectedRow();//库单选择行
    			tableModel_left.setValueAt(memberName,selectRow,3);//更改ID，姓名
    			if("null".equals(memberID)) memberID=null;
    			tableModel_left.setValueAt(memberID,selectRow,2);
    			tableModel_left.setValueAt(sell_date,selectRow,4);
    			tableModel_left.setValueAt(note,selectRow,5);
    			dispose();
			});
			c.add(bt_sure);
			//5.1取消
			insertJLabel(250, 20, c);//调整间距
			bt_cancel=createJButton("取消");
			bt_cancel.addActionListener(e->{
				dispose();
			});
			c.add(bt_cancel);
			
			init(libListMap);//填充修改前数据
			setTitle("批发单修改");
			setSize(700, 360);
			setResizable(false);// 不可增加大小
			setLocationRelativeTo(null);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setVisible(true);
		}
		
		
	}

	/**
	 * 增加商品界面
	 * 
	 * @author ZC
	 *
	 */
	public class Goodsfarme extends JDialog {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		private JPanel pl;
		// 北部
		private JPanel pl_north;
		private JButton bt_query;
		private JButton bt_sure;
		private JButton bt_cancel;
		private JComboBox<String> cbx_type;// 书的种类
		// 中部
		private JPanel pl_center_right;
		// 表格
		private DefaultTableModel tableModel;
		private JTable table;
		// 南部
		private JPanel pl_south;

		// 选中库单的时间
		String[] columnNames_right = { "书号","书名", "作者", "定价", "现有数量"};// 表格头
		// 边框
		private Border border = BorderFactory.createMatteBorder(0, 0, 3, 2, Color.gray);
		// 颜色
		private Color blue = new Color(0x9FB6CD);
		// 图片
		private ImageIcon img_query = new ImageIcon(MemberQuery.class.getResource("11.png"));
		JLabel temp;// 调整间距用的透明标签

		/**
		 * 商品查询界面
		 * 
		 * @param sellJFrame
		 * @param modal
		 * @param type
		 */
		public Goodsfarme(JDialog sellJFrame, boolean modal,Map<String ,String>  goodsMap)  {
			super(sellJFrame, modal);
			Container c = getContentPane();
			c.setLayout(new BorderLayout());
			/* 整个面板 */
			pl = new JPanel();
			pl.setBackground(Color.WHITE);
			pl.setLayout(new BorderLayout());

			/* 顶部 */
			pl_north = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 15));
			pl_north.setBackground(blue);
			pl_north.setPreferredSize(new Dimension(0, 50));
			c.add(BorderLayout.NORTH, pl_north);
			// 1查询标签
			JLabel lb_query = new JLabel("书名:");
			lb_query.setFont(new Font("楷体", Font.BOLD, 15));
			pl_north.add(lb_query);
			// 1.2查询输入框
			JTextField tf_query = new JTextField(10);
			tf_query.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			tf_query.setFont(new Font("宋体", Font.PLAIN, 15));
			tf_query.setPreferredSize(new Dimension(0, 25));
			pl_north.add(tf_query);
			// 1.4按类型查
			JLabel lb_type = new JLabel("种类:");
			lb_type.setFont(new Font("楷体", Font.BOLD, 15));
			pl_north.add(lb_type);
			String type1[] = { "教辅", "文学", "天文", "地理", "考试", "历史", "音乐", "人文", "其他" };
			cbx_type = new JComboBox<String>();
			for (int i = 0; i < type1.length; i++) {
				cbx_type.addItem(type1[i]);
			}
			cbx_type.setPreferredSize(new Dimension(80, 28));
			cbx_type.setBackground(new Color(0xFCFCFC));
			cbx_type.setFont(new Font("宋体", Font.PLAIN, 18));
			cbx_type.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.white, Color.gray));
			pl_north.add(cbx_type);
			// 1.3间距
			temp = new JLabel();
			temp.setPreferredSize(new Dimension(20, 12));
			pl_north.add(temp);
			// 1.4查询按钮
			bt_query = new JButton(img_query);
			bt_query.setPreferredSize(new Dimension(90, 30));
			bt_query.setFont(new Font("楷体", Font.BOLD, 15));
			bt_query.setBackground(new Color(0xF0F0F0));
			bt_query.setBorder(border);
			bt_query.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			bt_query.addActionListener(e -> {
				// 数据库查询
				tableModel.setDataVector(null, columnNames_right);//清空数据
				String sql="select id,BookName,author,price,inventoryNums from bookinfo where ";
				List<Object> params=new ArrayList<Object>();
				String bookName=tf_query.getText();
				String bookType=cbx_type.getSelectedItem()+"";
				if(!(bookName==null||bookName.length()==0||"".equals(bookName))) {
					sql+=" BookName like ? and type=?";
					params.add("%"+bookName+"%");
					params.add(bookType);
				}else {
					sql+=" type=?";
					params.add(bookType);
				}
				try {
					List<Object[]> data=base.queryArrayListHandler(sql,params.toArray());//获取所有书籍
				    for(int i=0;i<data.size();i++) {
				    	tableModel.addRow(data.get(i));
				    }
				    JOptionPane.showMessageDialog(Goodsfarme.this,"查询成功,共"+data.size()+"条数据");
				} catch (Exception e2) {
					// TODO: handle exception
					e2.printStackTrace();
				}
			});
			pl_north.add(bt_query);
			temp = new JLabel();
			temp.setPreferredSize(new Dimension(200, 12));// 设置间距
			pl_north.add(temp);
			// 4.订购数量
			// 4.1标签
			JLabel lb_sellNum = new JLabel("订购数量:");
			lb_sellNum.setFont(new Font("楷体", Font.BOLD, 15));
			pl_north.add(lb_sellNum);
			// 4.2输入框
			JTextField tf_sellNum = new JTextField(10);
			tf_sellNum.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			tf_sellNum.setFont(new Font("宋体", Font.PLAIN, 15));
			tf_sellNum.setPreferredSize(new Dimension(0, 25));
			pl_north.add(tf_sellNum);
			// 间距
			temp = new JLabel();
			temp.setPreferredSize(new Dimension(10, 12));// 设置间距
			pl_north.add(temp);
			// 2.确认
			bt_sure = new JButton("确认");
			bt_sure.setPreferredSize(new Dimension(80, 30));
			bt_sure.setFont(new Font("楷体", Font.BOLD, 15));
			bt_sure.setBackground(new Color(0xF0F0F0));
			bt_sure.setBorder(border);
			bt_sure.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			bt_sure.addActionListener(e -> {
				int selectRow = -1;
				if ((selectRow = table.getSelectedRow()) != -1) {// 已选
					String bookType = (String) cbx_type.getSelectedItem();
					String bookNum = tableModel.getValueAt(selectRow, 0)+"";//书号
					String bookName = tableModel.getValueAt(selectRow, 1)+"";
					String bookAuthor =tableModel.getValueAt(selectRow, 2)+"";
					int bookNumOfLib = Integer.parseInt(tableModel.getValueAt(selectRow, 4)+"");// 库存数量
					try {
						String bookPrice =tableModel.getValueAt(selectRow, 3)+"";
						int bookNumOfSell = Integer.parseInt(tf_sellNum.getText());// 售卖数量
						if (bookNumOfSell > bookNumOfLib || bookNumOfSell <= 0)//订购数量不合理
							throw new Exception("订购数量范围错误");
						goodsMap.put("bookNum",bookNum);
						goodsMap.put("bookName",bookName);
						goodsMap.put("bookAuthor",bookAuthor);
						goodsMap.put("bookPrice",bookPrice);
						goodsMap.put("bookNumOfLib",bookNumOfLib+"");
						goodsMap.put("bookType",bookType);
						goodsMap.put("bookNumOfSell",bookNumOfSell+"");
						tableModel.setValueAt(bookNumOfLib - bookNumOfSell + "", selectRow, 3);// 设置（减少）现有图书数量//////////////////////////////////////检查///////////////////////////////////////////////////////////////
						dispose();
					} catch (Exception e2) {
						JOptionPane.showMessageDialog(null, "请输入订购数量且数量小于等于"+bookNumOfLib, "错误",
								JOptionPane.ERROR_MESSAGE);
						return;
					}
				} else {
					JOptionPane.showMessageDialog(Goodsfarme.this, "请选中商品");
				}
			});
			pl_north.add(bt_sure);
			// 3.取消
			bt_cancel = new JButton("取消");
			bt_cancel.setPreferredSize(new Dimension(80, 30));
			bt_cancel.setFont(new Font("楷体", Font.BOLD, 15));
			bt_cancel.setBackground(new Color(0xF0F0F0));
			bt_cancel.setBorder(border);
			bt_cancel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			bt_cancel.addActionListener(e -> {
				dispose();
			});
			pl_north.add(bt_cancel);

			// 右边
			pl_center_right = new JPanel(new BorderLayout());
			pl_center_right.setBackground(Color.white);
			c.add(BorderLayout.CENTER, pl_center_right);
			// 表格
			tableModel = new DefaultTableModel(columnNames_right, 0);
			table = new JTable(tableModel);
			JScrollPane sp_center_right = new JScrollPane(table);
			sp_center_right.getViewport().setOpaque(false);
			sp_center_right.setBackground(Color.WHITE);
			pl_center_right.add(BorderLayout.CENTER, sp_center_right);

			/* 底部 */
			pl_south = new JPanel(null);
			pl_south = new JPanel(new FlowLayout(FlowLayout.CENTER, 30, 10));
			pl_south.setBackground(blue);
			pl_south.setPreferredSize(new Dimension(0, 60));
			c.add(BorderLayout.SOUTH, pl_south);

			fillData();// 填充数据
			setTitle("图书查询");
			setSize(1025, 685);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setLocationRelativeTo(sellJFrame);
			setVisible(true);

		}
		/**
		 * 填充数据
		 */
		public void fillData() {
			//换成数据库操作即可
			try {
				List<Object[]> data=base.queryArrayListHandler("select id,BookName,author,price,inventoryNums from bookinfo");//获取所有书籍
			    for(int i=0;i<data.size();i++) {
			    	tableModel.addRow(data.get(i));
			    }
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 选择客户界面
	 * 
	 * @author ZC
	 *
	 */
	public class ChooseMember extends JDialog {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		private JPanel pl;
		// 北部
		private JPanel pl_north;
		private JButton bt_query;// 会员查询按钮
		private JButton bt_other;// 非会员
		private JButton bt_sure;// 确认
		private JButton bt_cancel;// 取消
		// 中部
		private JPanel pl_center_right;
		// 表格
		String[] columnNames_right = {"编号","会员号", "姓名","电话号码", "余额", "折扣", "创建时间" };// 表头
		private DefaultTableModel tableModel_right;
		private JTable table_right;
		// 南部
		private JPanel pl_south;
		// 边框
		private Border border = BorderFactory.createMatteBorder(0, 0, 3, 2, Color.gray);
		// 颜色
		private Color blue = new Color(0x9FB6CD);
		/**
		 *1. 填充会员数据（后面改为数据库即可）
		 */
		public void fillData() {
			try {
				String sql="select id,accountNumber,name,tel,balance,discount,creactTime from client";
				List<Object[]> data=base.queryArrayListHandler(sql);
				for(int i=0;i<data.size();i++)
					tableModel_right.addRow(data.get(i));
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		/**
		 * 2.创建按钮
		 */
		public JButton createJButton(String text) {
			JButton bt = new JButton(text);// img_query
			bt.setPreferredSize(new Dimension(90, 30));
			bt.setFont(new Font("楷体", Font.BOLD, 15));
			bt.setBackground(new Color(0xF0F0F0));
			bt.setBorder(border);
			bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			return bt;
		}
		/**
		 * 3.插入标签调整距离(仅flow布局)
		 */
		public void insertJLabel(int length,JPanel pl) {
			JLabel lb=new JLabel();
			lb.setPreferredSize(new Dimension(length,1));
			pl.add(lb);
		}
        /**
         * 4. 选择客户面板（ 构造方法）
         * @param owner
         * @param modal
         * @param memberMap 客户信息
         */
		public ChooseMember(JDialog owner, boolean modal,Map<String,String> memberMap) {
			super(owner, modal);
			Container c = getContentPane();
			c.setLayout(new BorderLayout());
			/* 整个面板 */
			pl = new JPanel();
			pl.setBackground(Color.WHITE);
			pl.setLayout(new BorderLayout());

			/* 顶部 */
			pl_north = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 15));
			pl_north.setBackground(blue);
			pl_north.setPreferredSize(new Dimension(0, 50));
			c.add(BorderLayout.NORTH, pl_north);
			
			// 1.查询标签
			JLabel lb_query = new JLabel("姓名:");
			lb_query.setFont(new Font("楷体", Font.BOLD, 15));
			pl_north.add(lb_query);
			// 1.查询输入框
			JTextField tf_query = new JTextField(10);
			tf_query.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			tf_query.setFont(new Font("宋体", Font.PLAIN, 15));
			tf_query.setPreferredSize(new Dimension(0, 25));
			pl_north.add(tf_query);
			// 1.1查询
			bt_query = createJButton("查询");// img_query
			bt_query.addActionListener(e -> {
				// 数据库查询
				// 数据库查询
				tableModel_right.setDataVector(null, columnNames_right);//清空数据
				String name=tf_query.getText();
//				if(name==null||name.length()==0||"".equals(name)) {
//					JOptionPane.showMessageDialog(ChooseMember.this,"请填写所要查询的姓名");
//					return ;
//				}
				String sql="select id,accountNumber,name,tel,balance,discount,creactTime from client where name like ?";
				try {
					List<Object[]> data=base.queryArrayListHandler(sql,"%"+name+"%");//获取人名
				    for(int i=0;i<data.size();i++) {
				    	tableModel_right.addRow(data.get(i));
				    }
				    JOptionPane.showMessageDialog(ChooseMember.this,"查询成功,共"+data.size()+"条数据");
				} catch (Exception e2) {
					// TODO: handle exception
					e2.printStackTrace();
				}
			});
			pl_north.add(bt_query);
			insertJLabel(20, pl_north);//调距离
			
			// 2.非会员
			bt_other =createJButton("未记录");
			bt_other.addActionListener(e -> {
				// 数据库查询
				memberMap.putIfAbsent("memberID", "");//会员号为""
				dispose();
			});
			pl_north.add(bt_other);
			
			//3.确认，取消(点击后，后续操作的地点。 1：修改入库信息界面的客户选择   2.批发销售的新增批发单按钮)
			//3.1确认
			insertJLabel(400, pl_north);
            bt_sure=createJButton("确认");
            bt_sure.addActionListener(e->{
            	int selectRow;
            	if((selectRow=table_right.getSelectedRow())!=-1) {
            		memberMap.put("memberID",tableModel_right.getValueAt(selectRow,0)+"");
            		memberMap.put("memberName",(String)tableModel_right.getValueAt(selectRow,2));
            		dispose();
            	}else {
            		JOptionPane.showMessageDialog(ChooseMember.this,"请先选择您所需查找的客户，或者点击非会员按钮");
            	}
            });
            pl_north.add(bt_sure);
            //3.2取消
            bt_cancel=createJButton("取消");
            bt_cancel.addActionListener(e->{
            	dispose();
            });
            pl_north.add(bt_cancel);
            
            
			//1.中部表格
			pl_center_right = new JPanel(new BorderLayout());
			pl_center_right.setBackground(Color.white);
			c.add(BorderLayout.CENTER, pl_center_right);
			//1.1表格模型
			tableModel_right = new DefaultTableModel(columnNames_right, 0) {//表格模型
				/**
				 * 
				 */
				private static final long serialVersionUID = 1L;
				@Override
				public boolean isCellEditable(int row, int column) {//表格不可编辑
					// TODO Auto-generated method stub
					return false;
				}
			};
			//1.2表格
			table_right = new JTable(tableModel_right);//表格
			
			TableUtils.interlacedColorChange(table_right,new Color(0xFFFFE0),new Color(0xFFFACD));
			//1.3滚动面板
			JScrollPane sp_center_right = new JScrollPane(table_right);
			sp_center_right.getViewport().setOpaque(false);
			sp_center_right.setBackground(Color.WHITE);
			pl_center_right.add(BorderLayout.CENTER, sp_center_right);

			/* 底部 */
			pl_south = new JPanel(null);
			pl_south = new JPanel(new FlowLayout(FlowLayout.CENTER, 30, 10));
			pl_south.setBackground(blue);
			pl_south.setPreferredSize(new Dimension(0, 20));
			c.add(BorderLayout.SOUTH, pl_south);

			fillData();//填充数据
			setTitle("客户查询");
			setSize(1025, 685);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setLocationRelativeTo(owner);
			setVisible(true);
		}
	}
}
